package co.fitstart.coach.web.controller.courseware;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.persistence.GenericDaoSupport;

import co.fitstart.coach.entity.security.Login;
import co.fitstart.coach.web.resolver.Secure;
import co.fitstart.entity.course.schedule.CourseSchedule;

@Controller
@RequestMapping(value = "/rounds")
public class CoursewareHomeController {
    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    @RequestMapping(value = "/{courseRoundId}/courseware/home", method = RequestMethod.GET)
    public ModelAndView list(@Secure Login login,
                             @PathVariable("courseRoundId") Long courseRoundId,
                             @RequestParam("scheduleId") Long scheduleId) {
        
        ModelAndView modelAndView = new ModelAndView("courseware/view/courseware-home");
        
        CourseSchedule courseSchedule = genericDaoSupport.load(CourseSchedule.class, scheduleId);
        
        modelAndView.addObject("courseRoundId", courseRoundId);
        modelAndView.addObject("courseSchedule", courseSchedule);
        
        return modelAndView;
        
    }
}
